Imports System
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Text

Imports DevExpress.ExpressApp
Imports DevExpress.ExpressApp.Actions
Imports DevExpress.Persistent.Base
Imports DevExpress.ExpressApp.Utils
Imports DevExpress.Persistent.Base.General
Imports DevExpress.ExpressApp.Editors
Imports DevExpress.ExpressApp.Security

Partial Public Class TaskActionsController
    Inherits ViewController

    'Partial Public Class TaskActionsController
    '    Inherits ViewController
    '    '...
    '    Private Sub TaskActionsController_Activated(ByVal sender As Object, ByVal e As EventArgs) _
    '    Handles MyBase.Activated
    '        SetTaskAction.Active.SetItemValue("SecurityAllowance", SecuritySystem.IsGranted( _
    '        New ObjectAccessPermission(GetType(DemoTask), _
    '        ObjectAccess.Write, ObjectAccessModifier.Allow)))
    '        '...
    '    End Sub
    'End Class


    Private setPriorityItem As ChoiceActionItem
    Private setStatusItem As ChoiceActionItem
    Public Sub New()
        MyBase.New()
        InitializeComponent()
        RegisterActions(components)
        SetTaskAction.Items.Clear()
        setPriorityItem = _
        New ChoiceActionItem( _
        CaptionHelper.GetMemberCaption(GetType(DemoTask), "Priority"), Nothing)
        SetTaskAction.Items.Add(setPriorityItem)
        FillItemWithEnumValues(setPriorityItem, GetType(Priority))
        setStatusItem = _
           New ChoiceActionItem(CaptionHelper.GetMemberCaption(GetType(DemoTask), "Status"), Nothing)
        SetTaskAction.Items.Add(setStatusItem)
        FillItemWithEnumValues(setStatusItem, GetType(TaskStatus))
    End Sub
    Private Sub FillItemWithEnumValues(ByVal parentItem As ChoiceActionItem, ByVal enumType As Type)
        For Each current As Object In System.Enum.GetValues(enumType)
            Dim ed As EnumDescriptor = New EnumDescriptor(enumType)
            Dim item As ChoiceActionItem = New ChoiceActionItem(ed.GetCaption(current), current)
            item.ImageName = ImageLoader.Instance.GetEnumValueImageName(current)
            parentItem.Items.Add(item)
        Next current
    End Sub

    Private Sub SetTaskAction_Execute( _
ByVal sender As Object, ByVal e As SingleChoiceActionExecuteEventArgs) _
Handles SetTaskAction.Execute
        Dim objectSpace As IObjectSpace = If( _
        TypeOf View Is ListView, Application.CreateObjectSpace(), View.ObjectSpace)
        Dim objectsToProcess As New ArrayList(e.SelectedObjects)
        If e.SelectedChoiceActionItem.ParentItem Is setPriorityItem Then
            For Each obj As Object In objectsToProcess
                Dim objInNewObjectSpace As DemoTask = CType( _
                objectSpace.GetObject(obj), DemoTask)
                objInNewObjectSpace.Priority = CType(e.SelectedChoiceActionItem.Data, Priority)
            Next obj
        Else
            If e.SelectedChoiceActionItem.ParentItem Is setStatusItem Then
                For Each obj As Object In objectsToProcess
                    Dim objInNewObjectSpace As DemoTask = CType( _
                    objectSpace.GetObject(obj), DemoTask)
                    objInNewObjectSpace.Status = CType(e.SelectedChoiceActionItem.Data, TaskStatus)
                Next obj
            End If
        End If
        If TypeOf View Is DetailView AndAlso (CType(View, DetailView)).ViewEditMode = _
        ViewEditMode.View Then
            objectSpace.CommitChanges()
        End If
        If TypeOf View Is ListView Then
            objectSpace.CommitChanges()
            View.ObjectSpace.Refresh()
        End If
    End Sub

End Class
